<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;

use App\Http\Requests;


class AskController extends CommonController
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $list = \DB::table('question')->paginate(5);//仅用于分页
        
        $reply = \DB::table('reply')->get();//回答
        
        foreach($list as $v){
            $v->uid = \DB::table('user')->where('id',$v->uid)->value('userName');
            $v->bid = "《".\DB::table('goodsdetail')->where('id',$v->bid)->value('goodName')."》";
        }
        
        return view('admin.aa.index',['list'=>$list,'reply'=>$reply]);
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
        $name = $_GET['name'];
        dd();
        //又可以搜人，又可以搜书名，那就两个表一起搜，然后整合到一个数组，接着输出；
        $data1 = \DB::table('user')->where('userName','like','%'.$name.'%')->get();
        $data2 = \DB::table('goodsdetail')->where('bookName','like','%'.$name.'%')->get();
        return "后面还没写呢";
        // return view('admin.comment.create');
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        
        return "hello";
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {   
        $data = \DB::table('reply')->where('pid',$id)->get();

        if($data){
            return 'hello';
        }else{
            return 'sorry';
        }
       
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
       
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //找到要删除的id的那条信息
        // dd($id);
        // $data = \DB::table('reply')->get(['pid']);
        // foreach($data as $v){
        //     if($id==$v->pid){
        //         $info = "先删了回复才能删我:)";
        //         return back()->with('err',$info);
        //     }
        // }
        
        $m = \DB::table('question')->where('id',$id)->delete();
        if($m){
            return view('admin.aa.info',['info'=>'删掉了！！']);
        }else{
            return view('admin.aa.info',['info'=>'没有删掉！！']);
        }
    }
}
